//
//  CXFirstDetailCollectionViewCell.m
//  ProjectOfBStage
//
//  Created by cuixin on 15/11/14.
//  Copyright © 2015年 cuixin. All rights reserved.
//

#import "CXFirstDetailCollectionViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

@implementation CXFirstDetailCollectionViewCell
-(void)dealloc{
    [_titleLabel release];
    [_imgView release];
    [_likeImage release];
    [_likeLabel release];
    [super dealloc];
}
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.imgView = [[UIImageView alloc] init];
        self.likeImage =[[UIImageView alloc] init];
        self.likeLabel = [[UILabel alloc] init];
        self.titleLabel = [[UILabel alloc] init];
        
        [self.imgView addSubview:self.likeLabel];
        [self.imgView addSubview:self.likeImage];
        [self.contentView addSubview:self.imgView];
        [self.contentView addSubview:self.titleLabel];
        
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        self.likeLabel.font = [UIFont systemFontOfSize:12];
        [self.likeLabel setTextColor:[UIColor whiteColor]];
        [self.likeImage setImage:[UIImage imageNamed:@"likeWhite.png"]];
        
        [_titleLabel release];
        [_imgView release];
        [_likeImage release];
        [_likeLabel release];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.imgView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - HEIGHT_PRO(20));
    self.likeImage.frame = CGRectMake(WIDTH_PRO(10), self.imgView.frame.size.height - HEIGHT_PRO(30), WIDTH_PRO(20), HEIGHT_PRO(20));
    self.likeLabel.frame = CGRectMake(self.likeImage.frame.origin.x + self.likeImage.frame.size. width, self.likeImage.frame.origin.y, WIDTH_PRO(40), self.likeImage.frame.size.height);
    self.titleLabel.frame = CGRectMake(self.imgView.frame.origin.x, self.imgView.frame.size.height + self.imgView.frame.origin.y, self.imgView.frame.size.width, HEIGHT_PRO(30));
}
-(void)setDetailModel:(CXFirstDetailModel *)detailModel{
    if (_detailModel != detailModel) {
        [_detailModel release];
        _detailModel = [detailModel retain];
    }
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:detailModel.pic] placeholderImage:[UIImage imageNamed:@"wait.png"]];
    self.likeLabel.text = detailModel.like_count;
    self.titleLabel.text = detailModel.name;
}

@end
